<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>地图信息采集</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include> 
	<style type="text/css">
	  .serach{
	      height: 31px !important;
	      margin-bottom: 10px;
	      margin-top: 10px;
	      width: 450px;
	  }
	  .searchButton{
	      height: 30px;
	      width: 80px;
	      border: 1px solid #3079ED;
	      background-color: #4D90FE;
	      background-image: -moz-linear-gradient(center top , #4D90FE, #4787ED);
	      margin-bottom: 10px;
	      margin-top: 10px;
	      vertical-align: middle;
	      cursor: pointer;
	  }
	  .search-white {
		    background: url("../images/hpimgs28.png") no-repeat scroll -51px 0 transparent;
		    height: 15px;
		    width: 15px;
		}
	</style>
<script type="text/javascript">
var map = null;
var geocoder = null; //地址解释器
$(function(){
	
	if($.browser.msie && ($.browser.version == 8.0 || $.browser.version == 9.0)){
		 var h  = $(self.parent.parent.frames['mainFrame']).height()-95; 
    	 $('#map_canvas').height(h);
    }
	if (GBrowserIsCompatible()) {
	        map= new GMap2(document.getElementById("map_canvas"));
	        map.setCenter(new GLatLng(34.161818161230386, 103.798828125), 5); //13为缩放级别，可以通过map.getZoom()获取。
	        map.enableScrollWheelZoom();
	        map.disableDoubleClickZoom();
	        geocoder =  new GClientGeocoder();
		    map.addControl(new GLargeMapControl());	//
		    
		    $.ajax({
	    		url : 'location!findLocation.do',
	    		dataType : 'json',
	    		success : function(data){
	    			for(var i=0 ; i<data.length ; i++){
		    			var point = new GLatLng( data[i].YAxis , data[i].XAxis);
		    			map.addOverlay(createMarker(point , data[i]));
	    			}
	    		}
	    	});
		    
		    var baseIcon= new GIcon(G_DEFAULT_ICON);
			baseIcon.iconSize= new GSize(20, 34);
			baseIcon.iconAnchor= new GPoint(19, 24);
				
	     	function createMarker(point , data) {
			    var letteredIcon= new GIcon(baseIcon);
			     letteredIcon.image= "../images/beachflag.png";
			     markerOptions= { icon:letteredIcon};
			    var marker= new GMarker(point, markerOptions);
			    GEvent.addListener(marker, "click", function() {
				       marker.openInfoWindowHtml(data.locationName);
				});
			    GEvent.addListener(marker, "dblclick" ,function(){
			    	$.omMessageBox.confirm({
		                title:'处理记录',
		                content:'您确定处理该记录吗？',
		                onClose:function(result){
		               	 if(result){
					    	$.ajax({
					    		url : 'location!delete.do',
					    		dataType : 'json',
					    		data : {locationId:data.id},
					    		success : function(value){
					    			if(value == '1') {
					    				$.omMessageTip.show({timeout : 2000,content : '删除成功！'});
					    				map.removeOverlay(marker);
					    			}else{
					    				$.omMessageTip.show({timeout : 2000,content : '删除失败！'});
					    			}
					    		}
					    	});
		               	 }
		                }
			    	});
			    });
			    return marker;
			}
		    
	       /**监控事件**/
	       var center
	       GEvent.addListener(map, "dblclick", function(overlay,lt) { 
	           if(!overlay){
	        	   var leftTarget = self.parent.parent.frames['deviceFrame'];
        		   var selected = leftTarget.$('#reordeteTreeMunm').omTree('getSelected',true);
	        	   if(selected == null || selected.text == ''){
	        		   $.omMessageBox.alert({content:'请选择设备菜单节点后再双击！'});
	        		   return;
	        	   }
	               center= map.getCenter();
	               $.ajax({
	            	   url : 'location!saveLocation.do',
	            	   type : 'post',
	            	   data : {location:lt.x+','+lt.y,nodeId:selected.id,locationName:selected.text},
	            	   success : function(data){
	            		   if(data == '1'){
	            			   $.omMessageTip.show({timeout : 2000,content : '设置成功！'});
	            			   map.addOverlay(createMarker(new GLatLng( lt.y , lt.x)));
	            		   }else{
	            			   $.omMessageTip.show({timeout : 2000,content : '设置失败，请尝试重新设置或联系管理员！'});
	            		   }
	            	   }
	               });
	           }
	      });
    }

   $('#searchButton').click(function(){
	     var inputValue = $('#search').val();
	     if (geocoder) {
	          geocoder.getLatLng(
	        	    inputValue,
		            function(point) {
		              if (!point) {
		            	  $.omMessageBox.alert({content:'没有找到地址：'+inputValue});
		              } else {
		                  map.setCenter(point, 10);
		              }
		            }
	          );
	        }
   });     
});

function function_002001004_tab(nodeData)
{
	var userData = nodeData.userData.split(',');
	if (geocoder && nodeData.id.indexOf('re_') != -1) { //只有区域才查找定位到指定地方
		if(userData && userData.length > 0){
  		    //$.omMessageTip.show({timeout : 2000,content : '已经抓取坐标'});
	  		geocoder.getLatLng(
	        		nodeData.text,
		            function(point) {
		              if (!point) {
		            	  $.omMessageBox.alert({content:'没有找到地址：'+nodeData.text});
		              } else {
		                  map.setCenter(point, 10);
		              }
		            }
	        );
  	    }else{
  		  //do nothing
  	    }
      }else{ //非区域的话，如果已经定制坐标就提示一下，没有定制的话就没有反应
    	  //if(userData && userData.length > 0){
    		//  $.omMessageTip.show({timeout : 2000,content : '已经抓取坐标'});
    	 // }else{
    		  //do nothing
    	 // }
      }
}

</script>   
  </head>
  <body onunload="GUnload()">
      <form>
		  <input type="text" id="search" class="serach"> 
	      <button type="button" title="搜索地图" class="searchButton" id="searchButton"> 
	        <img class="search-white" src="//maps.gstatic.com/mapfiles/transparent.png">
	      </button> 
	      <div style="float: right;font-size: 16px;margin-top: 15px;color: blue;">请选择右边设备菜单中的地址，在地图上双击设置地理位置值</div>
		  <div id="map_canvas" style="width: 100%;"></div>
	  </form>
  </body>
</html>
